﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace JBoxPhotobooth
{
    public partial class FormBACKOFFICE : Form
    {
        protected GLS.BUSSINES.MASTER.GLS_USER bUser = new GLS.BUSSINES.MASTER.GLS_USER();
        protected GLS.COMMON.MASTER.GLS_USER cUser = new GLS.COMMON.MASTER.GLS_USER();


        public FormBACKOFFICE(GLS.COMMON.MASTER.GLS_USER obj)
        {
            InitializeComponent();
            cUser = obj;
            LOAD_PC();
        }
        void LOAD_PC()
        {
            Microsoft.VisualBasic.Devices.ServerComputer PC = new Microsoft.VisualBasic.Devices.ServerComputer();
            string Komp = PC.Name;
            string strHostName = "";

            strHostName = System.Net.Dns.GetHostName();
            /*
            IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;

            if (addr.Count() == 4)
            {
                tsPC.Text = Komp +" - "+ addr[2].ToString();
            }
            if (addr.Count() == 2)
            {
                tsPC.Text = Komp + " - " + addr[1].ToString();
            }
             */
            tsPC.Text = Komp + "-" + LocalIPAddress();
        }
        private IPAddress LocalIPAddress()
        {
            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                return null;
            }

            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());

            return host
                .AddressList
                .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
        }
        private void CLEAR_PANEL()
        {
            foreach (Control ctrl in panelMENU.Controls)
            {
                ctrl.Visible = false;
            }
        }
         public void SettForm(Form frm)
        {
            frm.TopLevel = false;
            frm.Visible = true;
            panelMENU.Controls.Add(frm);
            panelMENU.Controls[frm.Name].Focus();
            frm.BringToFront();
        }

         private void voucherPhotoToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (cUser.isaktif)
             {
                 CLEAR_PANEL();
                 FormVOUCHERPHOTO frm = new JBoxPhotobooth.FormVOUCHERPHOTO(cUser);
                 SettForm(frm);
             }
             else
             {
                 MessageBox.Show("Maaf anda tidak mempunyai akses ke modul ini, segera hubungi bagian terkait", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             }
             
         }
    }
}
